home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / info.test < prev    next >
Text File  |  1993-06-18  |  15KB  |  516 lines

  1. # Commands covered:  info
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/info.test,v 1.16 93/06/18 13:50:51 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. test info-1.1 {info args option} {
  32.     proc t1 {a bbb c} {return foo}
  33.     info args t1
  34. } {a bbb c}
  35. test info-1.2 {info args option} {
  36.     proc t1 {{a default1} {bbb default2} {c default3} args} {return foo}
  37.     info a t1
  38. } {a bbb c args}
  39. test info-1.3 {info args option} {
  40.     proc t1 "" {return foo}
  41.     info args t1
  42. } {}
  43. test info-1.4 {info args option} {
  44.     catch {rename t1 {}}
  45.     list [catch {info args t1} msg] $msg
  46. } {1 {"t1" isn't a procedure}}
  47. test info-1.5 {info args option} {
  48.     list [catch {info args set} msg] $msg
  49. } {1 {"set" isn't a procedure}}
  50.  
  51. test info-2.1 {info body option} {
  52.     proc t1 {} {body of t1}
  53.     info body t1
  54. } {body of t1}
  55. test info-2.2 {info body option} {
  56.     list [catch {info body set} msg] $msg
  57. } {1 {"set" isn't a procedure}}
  58. test info-2.3 {info body option} {
  59.     list [catch {info args set 1} msg] $msg
  60. } {1 {wrong # args: should be "info args procname"}}
  61.  
  62. test info-3.1 {info cmdcount option} {
  63.     set x [info cmdcount]
  64.     set y 12345
  65.     set z [info cm]
  66.     expr $z-$x
  67. } 3
  68. test info-3.2 {info body option} {
  69.     list [catch {info cmdcount 1} msg] $msg
  70. } {1 {wrong # args: should be "info cmdcount"}}
  71.  
  72. test info-4.1 {info commands option} {
  73.     proc t1 {} {}
  74.     proc t2 {} {}
  75.     set x " [info commands] "
  76.     list [string match {* t1 *} $x] [string match {* t2 *} $x] \
  77.             [string match {* set *} $x] [string match {* list *} $x]
  78. } {1 1 1 1}
  79. test info-4.2 {info commands option} {
  80.     proc t1 {} {}
  81.     rename t1 {}
  82.     set x [info comm]
  83.     string match {* t1 *} $x
  84. } 0
  85. test info-4.3 {info commands option} {
  86.     proc _t1_ {} {}
  87.     proc _t2_ {} {}
  88.     info commands _t1_
  89. } _t1_
  90. test info-4.4 {info commands option} {
  91.     proc _t1_ {} {}
  92.     proc _t2_ {} {}
  93.     lsort [info commands _t*]
  94. } {_t1_ _t2_}
  95. catch {rename _t1_ {}}
  96. catch {rename _t2_ {}}
  97. test info-4.5 {info commands option} {
  98.     list [catch {info commands a b} msg] $msg
  99. } {1 {wrong # args: should be "info commands [pattern]"}}
  100.  
  101. test info-5.1 {info complete option} {
  102.     info complete ""
  103. } 1
  104. test info-5.2 {info complete option} {
  105.     info complete "  \n"
  106. } 1
  107. test info-5.3 {info complete option} {
  108.     info complete "abc def"
  109. } 1
  110. test info-5.4 {info complete option} {
  111.     info complete "a b c d e f \t\n"
  112. } 1
  113. test info-5.5 {info complete option} {
  114.     info complete {a b c"d}
  115. } 1
  116. test info-5.6 {info complete option} {
  117.     info complete {a b "c d" e}
  118. } 1
  119. test info-5.7 {info complete option} {
  120.     info complete {a b "c d"}
  121. } 1
  122. test info-5.8 {info complete option} {
  123.     info complete {a b "c d"}
  124. } 1
  125. test info-5.9 {info complete option} {
  126.     info complete {a b "c d}
  127. } 0
  128. test info-5.10 {info complete option} {
  129.     info complete {a b "}
  130. } 0
  131. test info-5.11 {info complete option} {
  132.     info complete {a b "cd"xyz}
  133. } 1
  134. test info-5.12 {info complete option} {
  135.     info complete {a b "c $d() d"}
  136. } 1
  137. test info-5.13 {info complete option} {
  138.     info complete {a b "c $dd("}
  139. } 0
  140. test info-5.14 {info complete option} {
  141.     info complete {a b "c \"}
  142. } 0
  143. test info-5.15 {info complete option} {
  144.     info complete {a b "c [d e f]"}
  145. } 1
  146. test info-5.16 {info complete option} {
  147.     info complete {a b "c [d e f] g"}
  148. } 1
  149. test info-5.17 {info complete option} {
  150.     info complete {a b "c [d e f"}
  151. } 0
  152. test info-5.18 {info complete option} {
  153.     info complete {a {b c d} e}
  154. } 1
  155. test info-5.19 {info complete option} {
  156.     info complete {a {b c d}}
  157. } 1
  158. test info-5.20 {info complete option} {
  159.     info complete "a b\{c d"
  160. } 1
  161. test info-5.21 {info complete option} {
  162.     info complete "a b \{c"
  163. } 0
  164. test info-5.22 {info complete option} {
  165.     info complete "a b \{c{ }"
  166. } 0
  167. test info-5.23 {info complete option} {
  168.     info complete "a b {c d e}xxx"
  169. } 1
  170. test info-5.24 {info complete option} {
  171.     info complete "a b {c \\\{d e}xxx"
  172. } 1
  173. test info-5.25 {info complete option} {
  174.     info complete {a b [ab cd ef]}
  175. } 1
  176. test info-5.26 {info complete option} {
  177.     info complete {a b x[ab][cd][ef] gh}
  178. } 1
  179. test info-5.27 {info complete option} {
  180.     info complete {a b x[ab][cd[ef] gh}
  181. } 0
  182. test info-5.28 {info complete option} {
  183.     info complete {a b x[ gh}
  184. } 0
  185. test info-5.29 {info complete option} {
  186.     info complete {[]]]}
  187. } 1
  188. test info-5.30 {info complete option} {
  189.     info complete {abc x$yyy}
  190. } 1
  191. test info-5.31 {info complete option} {
  192.     info complete "abc x\${abc\[\\d} xyz"
  193. } 1
  194. test info-5.32 {info complete option} {
  195.     info complete "abc x\$\{ xyz"
  196. } 0
  197. test info-5.33 {info complete option} {
  198.     info complete {word $a(xyz)}
  199. } 1
  200. test info-5.34 {info complete option} {
  201.     info complete {word $a(}
  202. } 0
  203. test info-5.35 {info complete option} {
  204.     info complete "set a \\\n"
  205. } 0
  206. test info-5.36 {info complete option} {
  207.     info complete "set a \\n "
  208. } 1
  209. test info-5.37 {info complete option} {
  210.     info complete "set a \\"
  211. } 1
  212. test info-5.38 {info complete option} {
  213.     info complete "foo \\\n\{"
  214. } 0
  215.  
  216. test info-6.1 {info default option} {
  217.     proc t1 {a b {c d} {e "long default value"}} {}
  218.     info default t1 a value
  219. } 0
  220. test info-6.2 {info default option} {
  221.     proc t1 {a b {c d} {e "long default value"}} {}
  222.     set value 12345
  223.     info d t1 a value
  224.     set value
  225. } {}
  226. test info-6.3 {info default option} {
  227.     proc t1 {a b {c d} {e "long default value"}} {}
  228.     info default t1 c value
  229. } 1
  230. test info-6.4 {info default option} {
  231.     proc t1 {a b {c d} {e "long default value"}} {}
  232.     set value 12345
  233.     info default t1 c value
  234.     set value
  235. } d
  236. test info-6.5 {info default option} {
  237.     proc t1 {a b {c d} {e "long default value"}} {}
  238.     set value 12345
  239.     set x [info default t1 e value]
  240.     list $x $value
  241. } {1 {long default value}}
  242. test info-6.6 {info default option} {
  243.     list [catch {info default a b} msg] $msg
  244. } {1 {wrong # args: should be "info default procname arg varname"}}
  245. test info-6.7 {info default option} {
  246.     list [catch {info default _nonexistent_ a b} msg] $msg
  247. } {1 {"_nonexistent_" isn't a procedure}}
  248. test info-6.8 {info default option} {
  249.     proc t1 {a b} {}
  250.     list [catch {info default t1 x value} msg] $msg
  251. } {1 {procedure "t1" doesn't have an argument "x"}}
  252. test info-6.9 {info default option} {
  253.     catch {unset a}
  254.     set a(0) 88
  255.     proc t1 {a b} {}
  256.     list [catch {info default t1 a a} msg] $msg
  257. } {1 {couldn't store default value in variable "a"}}
  258. test info-6.10 {info default option} {
  259.     catch {unset a}
  260.     set a(0) 88
  261.     proc t1 {{a 18} b} {}
  262.     list [catch {info default t1 a a} msg] $msg
  263. } {1 {couldn't store default value in variable "a"}}
  264. catch {unset a}
  265.  
  266. test info-7.1 {info exists option} {
  267.     set value foo
  268.     info exists value
  269. } 1
  270. catch {unset _nonexistent_}
  271. test info-7.2 {info exists option} {
  272.     info exists _nonexistent_
  273. } 0
  274. test info-7.3 {info exists option} {
  275.     proc t1 {x} {return [info exists x]}
  276.     t1 2
  277. } 1
  278. test info-7.4 {info exists option} {
  279.     proc t1 {x} {
  280.         global _nonexistent_
  281.         return [info exists _nonexistent_]
  282.     }
  283.     t1 2
  284. } 0
  285. test info-7.5 {info exists option} {
  286.     proc t1 {x} {
  287.         set y 47
  288.         return [info exists y]
  289.     }
  290.     t1 2
  291. } 1
  292. test info-7.6 {info exists option} {
  293.     proc t1 {x} {return [info exists value]}
  294.     t1 2
  295. } 0
  296. test info-7.7 {info exists option} {
  297.     catch {unset x}
  298.     set x(2) 44
  299.     list [info exists x] [info exists x(1)] [info exists x(2)]
  300. } {1 0 1}
  301. catch {unset x}
  302. test info-7.8 {info exists option} {
  303.     list [catch {info exists} msg] $msg
  304. } {1 {wrong # args: should be "info exists varName"}}
  305. test info-7.9 {info exists option} {
  306.     list [catch {info exists 1 2} msg] $msg
  307. } {1 {wrong # args: should be "info exists varName"}}
  308.  
  309. test info-8.1 {info globals option} {
  310.     set x 1
  311.     set y 2
  312.     set value 23
  313.     set a " [info globals] "
  314.     list [string match {* x *} $a] [string match {* y *} $a] \
  315.             [string match {* value *} $a] [string match {* _foobar_ *} $a]
  316. } {1 1 1 0}
  317. test info-8.2 {info globals option} {
  318.     set _xxx1 1
  319.     set _xxx2 2
  320.     lsort [info g _xxx*]
  321. } {_xxx1 _xxx2}
  322. test info-8.3 {info globals option} {
  323.     list [catch {info globals 1 2} msg] $msg
  324. } {1 {wrong # args: should be "info globals [pattern]"}}
  325.  
  326. test info-9.1 {info level option} {
  327.     info level
  328. } 0
  329. test info-9.2 {info level option} {
  330.     proc t1 {a b} {
  331.         set x [info le]
  332.         set y [info level 1]
  333.         list $x $y
  334.     }
  335.     t1 146 testString
  336. } {1 {t1 146 testString}}
  337. test info-9.3 {info level option} {
  338.     proc t1 {a b} {
  339.         t2 [expr $a*2] $b
  340.     }
  341.     proc t2 {x y} {
  342.         list [info level] [info level 1] [info level 2] [info level -1] \
  343.                 [info level 0]
  344.     }
  345.     t1 146 {a {b c} {{{c}}}}
  346. } {2 {t1 146 {a {b c} {{{c}}}}} {t2 292 {a {b c} {{{c}}}}} {t1 146 {a {b c} {{{c}}}}} {t2 292 {a {b c} {{{c}}}}}}
  347. test info-9.4 {info level option} {
  348.     proc t1 {} {
  349.         set x [info level]
  350.         set y [info level 1]
  351.         list $x $y
  352.     }
  353.     t1
  354. } {1 t1}
  355. test info-9.5 {info level option} {
  356.     list [catch {info level 1 2} msg] $msg
  357. } {1 {wrong # args: should be "info level [number]"}}
  358. test info-9.6 {info level option} {
  359.     list [catch {info level 123a} msg] $msg
  360. } {1 {expected integer but got "123a"}}
  361. test info-9.7 {info level option} {
  362.     list [catch {info level 0} msg] $msg
  363. } {1 {bad level "0"}}
  364. test info-9.8 {info level option} {
  365.     proc t1 {} {info level -1}
  366.     list [catch {t1} msg] $msg
  367. } {1 {bad level "-1"}}
  368. test info-9.9 {info level option} {
  369.     proc t1 {x} {info level $x}
  370.     list [catch {t1 -3} msg] $msg
  371. } {1 {bad level "-3"}}
  372.  
  373. test info-10.1 {info library option} {
  374.     list [catch {info library x} msg] $msg
  375. } {1 {wrong # args: should be "info library"}}
  376. # The following check can only be done at Berkeley, where the exact
  377. # location of the library is known.
  378.  
  379. if $atBerkeley {
  380.     test info-10.2 {info library option} {
  381.     info li
  382.     } /users/ouster/tcl/library
  383.     test info-10.3 {info library option} {
  384.     set env(TCL_LIBRARY) test_value
  385.     set result [info library]
  386.     unset env(TCL_LIBRARY)
  387.     list $result [info library]
  388.     } {test_value /users/ouster/tcl/library}
  389. }
  390.  
  391. test info-11.1 {info locals option} {
  392.     set a 22
  393.     proc t1 {x y} {
  394.         set b 13
  395.         set c testing
  396.         global a
  397.         return [info locals]
  398.     }
  399.     lsort [t1 23 24]
  400. } {b c x y}
  401. test info-11.2 {info locals option} {
  402.     proc t1 {x y} {
  403.         set xx1 2
  404.         set xx2 3
  405.         set y 4
  406.         return [info lo x*]
  407.     }
  408.     lsort [t1 2 3]
  409. } {x xx1 xx2}
  410. test info-11.3 {info locals option} {
  411.     list [catch {info locals 1 2} msg] $msg
  412. } {1 {wrong # args: should be "info locals [pattern]"}}
  413. test info-11.4 {info locals option} {
  414.     info locals
  415. } {}
  416. test info-11.5 {info locals option} {
  417.     proc t1 {} {return [info locals]}
  418.     t1
  419. } {}
  420.  
  421. test info-12.1 {info patchlevel option} {
  422.     set a [info patchlevel]
  423.     incr a 2
  424.     expr $a-[info patchlevel]
  425. } 2
  426. test info-12.2 {info patchlevel option} {
  427.     list [catch {info patchlevel a} msg] $msg
  428. } {1 {wrong # args: should be "info patchlevel"}}
  429.  
  430. test info-13.1 {info procs option} {
  431.     proc t1 {} {}
  432.     proc t2 {} {}
  433.     set x " [info procs] "
  434.     list [string match {* t1 *} $x] [string match {* t2 *} $x] \
  435.             [string match {* _undefined_ *} $x]
  436. } {1 1 0}
  437. test info-13.2 {info procs option} {
  438.     proc _tt1 {} {}
  439.     proc _tt2 {} {}
  440.     lsort [info pr _tt*]
  441. } {_tt1 _tt2}
  442. catch {rename _tt1 {}}
  443. catch {rename _tt2 {}}
  444. test info-13.3 {info procs option} {
  445.     list [catch {info procs 2 3} msg] $msg
  446. } {1 {wrong # args: should be "info procs [pattern]"}}
  447.  
  448. test info-14.1 {info script option} {
  449.     list [catch {info script x} msg] $msg
  450. } {1 {wrong # args: should be "info script"}}
  451. test info-14.2 {info script option} {
  452.     file tail [info s]
  453. } info.test
  454. catch {exec rm -f gorp.info}
  455. exec cat > gorp.info << "info script\n"
  456. test info-14.3 {info script option} {
  457.     list [source gorp.info] [file tail [info script]]
  458. } {gorp.info info.test}
  459. test info-14.4 {resetting "info script" after errors} {
  460.     catch {source ~_nobody_/foo}
  461.     file tail [info script]
  462. } {info.test}
  463. test info-14.5 {resetting "info script" after errors} {
  464.     catch {source _nonexistent_}
  465.     file tail [info script]
  466. } {info.test}
  467. exec rm -f gorp.info
  468.  
  469. test info-15.1 {info tclversion option} {
  470.     set x [info tclversion]
  471.     scan $x "%d.%d%c" a b c
  472. } 2
  473. test info-15.2 {info tclversion option} {
  474.     list [catch {info t 2} msg] $msg
  475. } {1 {wrong # args: should be "info tclversion"}}
  476.  
  477. test info-16.1 {info vars option} {
  478.     set a 1
  479.     set b 2
  480.     proc t1 {x y} {
  481.         global a b
  482.         set c 33
  483.         return [info vars]
  484.     }
  485.     lsort [t1 18 19]
  486. } {a b c x y}
  487. test info-16.2 {info vars option} {
  488.     set xxx1 1
  489.     set xxx2 2
  490.     proc t1 {xxa y} {
  491.         global xxx1 xxx2
  492.         set c 33
  493.         return [info vars x*]
  494.     }
  495.     lsort [t1 18 19]
  496. } {xxa xxx1 xxx2}
  497. test info-16.3 {info vars option} {
  498.     lsort [info vars]
  499. } [lsort [info globals]]
  500. test info-16.4 {info vars option} {
  501.     list [catch {info vars a b} msg] $msg
  502. } {1 {wrong # args: should be "info vars [pattern]"}}
  503.  
  504. test info-17.1 {miscellaneous error conditions} {
  505.     list [catch {info} msg] $msg
  506. } {1 {wrong # args: should be "info option ?arg arg ...?"}}
  507. test info-17.2 {miscellaneous error conditions} {
  508.     list [catch {info gorp} msg] $msg
  509. } {1 {bad option "gorp": should be args, body, cmdcount, commands, complete, default, exists, globals, level, library, locals, patchlevel, procs, script, tclversion, or vars}}
  510. test info-17.3 {miscellaneous error conditions} {
  511.     list [catch {info c} msg] $msg
  512. } {1 {bad option "c": should be args, body, cmdcount, commands, complete, default, exists, globals, level, library, locals, patchlevel, procs, script, tclversion, or vars}}
  513. test info-17.4 {miscellaneous error conditions} {
  514.     list [catch {info l} msg] $msg
  515. } {1 {bad option "l": should be args, body, cmdcount, commands, complete, default, exists, globals, level, library, locals, patchlevel, procs, script, tclversion, or vars}}
  516.